package com.boost.bio.line;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.List;

public class NormalReadLine implements ReadLine {

    private BufferedReader bufferedReader;

    private String splitFiled;

    private MyInputStream myInputStream;

    public NormalReadLine(String filePath) throws IOException {
        this(filePath, "|");
    }

    public NormalReadLine(String filePath, String splitFiled) throws IOException {
        myInputStream = new MyInputStream(filePath);
        bufferedReader = new BufferedReader(new InputStreamReader(myInputStream.getInputStream(),Charset.forName("UTF-8")));
        this.splitFiled = splitFiled;
    }

    @Override
    public List<String> read() throws IOException {
        String s = bufferedReader.readLine();
        if (s == null) {
            return null;
        }
        return Arrays.asList(s.split(splitFiled));
    }

    @Override
    public void close() throws IOException {
        bufferedReader.close();
        myInputStream.close();
    }
}
